
set more off
clear all
set mem 3g

local path0="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\"

cd "`path0'Data\IPUMS_2000"

* Import bridge from ethnicity to country level data
insheet using "Bridge to country level.txt", names tab
compress
drop if ancestr1==.
drop n2000
drop ethnicity_name
save Bridge_ancestr1, replace

rename ancestr1 ancestr2
rename countrycode countrycode2
save Bridge_ancestr2, replace

use usa_00004, clear

* merge with the ethnic bridge for ethnic-country pairs
rename ancestr1 ancestr1A
rename ancestr1d ancestr1
joinby ancestr1 using Bridge_ancestr1, unmatched(master)
tab _merge 
drop _merge

rename ancestr2 ancestr2A
rename ancestr2d ancestr2
joinby ancestr2 using Bridge_ancestr2, unmatched(master)
tab _merge 
drop _merge

gen USborn=(bpl<100) if bpl~=.

* merge with the data on individualism
joinby countrycode using ///
	"`path0'data\Culture_measures\idv_updated.dta" , unmatched(master)



*=======================================================================
gen science_sector=(ind==746 | ind==787) if ind~=.
gen science_occupation=(occ==160 | occ==161 | occ==164 | occ==165 | ///
		occ==170 | occ==171 | occ==172 | occ==173 | occ==174 | occ==175 ///
		| occ==176 | occ==180 | occ==181 | occ==186 | occ==190 | occ==191 | occ==192 | occ==193 | occ==194) if occ~=.

gen science_occupationA=(occ>=130 & occ<200) | occ==121 if occ~=.

/*
160  	160  	Agricultural and Food Scientists
161 	161 	Biological Scientists
164 	164 	Conservation Scientists and Foresters
165 	165 	Medical Scientists
170 	170 	Astronomers and Physicists
171 	171 	Atmospheric and Space Scientists
172 	172 	Chemists and Materials Scientists
173 	173 	Not used
174 	174 	Environmental Scientists and Geoscientists
175 	175 	Not used
176 	176 	Physical Scientists, All Other
180 	180 	Economists
181 	181 	Market and Survey Researchers
182 	182 	Psychologists
183 	(See code 186) 	Sociologists
184 	184 	Urban and Regional Planners
185 	185 	Not used
186 	186 (Includes 183) 	Miscellaneous Social Scientists, Including Sociologists
190 	190 	Agricultural and Food Science Technicians
191 	191 	Biological Technicians
192 	192 	Chemical Technicians
193 	193 	Geological and Petroleum Technicians
194 	(See code 196) 	Nuclear Technicians
*/

compress

* keep only observatons with known ancestors
keep if idv~=.

*keep only employed individuals with non-missing occupation or industry
keep if occ~=. | ind~=.

* keep only working age people
keep if age>=25 & age<=60

* drop individuals who attend a school
drop if school==2
drop school

compress



drop ind1990 occ1990
drop wkswork* uhrswork workedyr
drop countrycode2
drop rac*
drop ancestr2*
drop datanum
drop _merge
drop gq
drop schltype
drop gradeatt*
drop city*
drop occscore  sei hwsei

*** do no include GBR: this is the benchmark
*** do not include USA: this is the "native" population
quiet foreach var in ///
		AGO ALB  ARE ARG AUS AUT BEL BFA BGD BGR BRA BTN CAN ///
		CHE CHL CHN COL CRI CZE DNK DOM ECU EGY ESP EST ETH FIN ///
		FJI FRA GBR GER GHA GRC GTM HND HRV HUN IDN IND IRL IRN ///
		IRQ ISL ISR ITA JAM JOR JPN KEN KOR KWT LBN LBY LKA LTU LUX ///
		LVA MAR MEX MLT MOZ MWI MYS NAM NGA NLD NOR NPL NZL PAK PAN ///
		PER PHL POL PRT ROM RUS SAU SCG SEN SLE SLV SVK SVN SWE ///
		SYR THA TTO TUR TWN TZA UKR URY VEN VNM ZAF ZMB  ///
		{
		
gen byte e_`var'=(countrycode=="`var'")
}

compress e_*

keep if sex==1
save temp_census002, replace

